<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Information as ModelInformation;
use think\Db;

/**
 * 系统消息
 */
class Information extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';

    /**
     * 消息列表
     */
    public function lists()
    {
        $page = $this->request->post('page', 1);
        $pageSize = $this->request->post('page_size', 10);
        $list = ModelInformation::where('status', 1)->order('create_time desc')->paginate($pageSize);
        foreach ($list as $row) {
            $row->images = !empty($row->images) ? config("app_url") . $row->images : '';
        }
        $this->success("请求成功", $list);
    }

    /**
     * 消息详情
     */
    public function details()
    {
        $id = $this->request->post('id', 0);

        if(!$id){
            $this->error("信息错误！");
        }

        $info = ModelInformation::where('id', $id)->find();
        $info->images = !empty($info->images) ? config("app_url") . $info->images : '';
        $this->success("请求成功", $info);
    }
}
